package application.controller;

import java.awt.event.*;
import javax.swing.*;

import application.model.*;

public class MenuController extends AbstractController implements ActionListener 
{
	private static final long serialVersionUID = 1L;
	private JMenuBar menuBar; 
	
	public MenuController(Simulator model)
	{
		super(model);
		this.menuBar = new JMenuBar();
		setSize(540,100);
		this.addMenu("Menu 1", new String[] {"Exit"}, new boolean[] {true});
		this.addMenu("Menu 2", new String[]{}, new boolean[]{} );
		this.addMenu("Help", new String[]{}, new boolean[]{} );
		
		add(this.menuBar);
		setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		System.out.println("menuitem clicked");
	}
	
	private void addMenu(String submenu, String[] submenuitems, boolean[] additemtoactionlistener)
	{
		JMenu subMenu = new JMenu(submenu);
		
		for(int menuItemIndex = 0; menuItemIndex < submenuitems.length; menuItemIndex++)
		{
			JMenuItem subMenuItem = new JMenuItem(submenuitems[menuItemIndex]);
			
			if(additemtoactionlistener[menuItemIndex])
			{
				subMenuItem.addActionListener(this);
			}
			
			subMenu.add(subMenuItem);
		}
		this.menuBar.add(subMenu);
	}
}
